#!/bin/bash

dl_path='/dl/java'
install_path='/basic/java'

makeDir() {
  mkdir -p $dl_path
  mkdir -p $install_path
}

install() {
  cd $install_path || exit
  yum -y install java-1.8.0-openjdk.x86_64
}

edit_profile() {
  local profile
  profile='/etc/profile'
  cat << 'EOF' >> $profile

#set java environment
JAVA_HOME=/usr/lib/jvm/jre
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH
EOF

  source '/etc/profile'
}

mkdir
install
edit_profile